EMUDIR := ./emu
LCDKEYDIR := ./lcdkey
DBDIR := ./db
COMDIR := ./common
SOCKETDIR := ./socket

CC := arm-linux-gcc
CFLAGS := -Wall -O2 -lm -lsqlite3 -lpthread -l645 -L ./lib -g -rdynamic
OBJ := emu2

EMU_SRCS := $(EMUDIR)/emu.o				#emu
LCDKEY_SRCS := $(LCDKEYDIR)/lcdkey.o	#lcdkey
DB_SRCS :=  $(DBDIR)/db.o				#db
COM_SRCS := $(COMDIR)/common.o			#common
SOCKET_SRCS := $(SOCKETDIR)/socket.o	#socket

all : $(OBJ)

$(OBJ) : $(EMU_SRCS) $(LCDKEY_SRCS) $(DB_SRCS) $(COM_SRCS) $(SOCKET_SRCS)
	$(CC) -o $(OBJ) $(CFLAGS) $(EMU_SRCS) $(LCDKEY_SRCS) $(DB_SRCS) $(COM_SRCS) $(SOCKET_SRCS)

$(EMU_SRCS):
	cd $(EMUDIR) && $(MAKE)
$(LCDKEY_SRCS):
	cd $(LCDKEYDIR) && $(MAKE)
$(DB_SRCS):
	cd $(DBDIR) && $(MAKE)
$(COM_SRCS):
	cd $(COMDIR) && $(MAKE)
$(SOCKET_SRCS):
	cd $(SOCKETDIR) && $(MAKE)

install:
	@cp emu2 /home/radionfs
clean:
	@rm -f $(OBJ) $(EMU_SRCS) $(LCDKEY_SRCS) $(DB_SRCS) $(COM_SRCS) $(SOCKET_SRCS)
	@rm -f /home/radionfs/emu.db
	@rm -f /home/radionfs/emu2
